package com.art.museumbackend.mapper;

import com.art.museumbackend.entity.Columns;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yezi
 * @since 2024-12-07
 */
@Mapper
public interface ColumnMapper extends BaseMapper<Columns> {
    @Insert("INSERT INTO `columns` (parent_id, name, description, image_url, image_width, image_height, type, created_time, updated_time) " +
            "VALUES (#{parentId}, #{name}, #{description}, #{imageUrl}, #{imageWidth}, #{imageHeight}, #{type}, #{createdTime}, #{updatedTime})")
    @Options(useGeneratedKeys = true, keyProperty = "columnId")
   void addColumn(Columns columns);

    @Select("SELECT * FROM `columns`")
    List<Columns> selectAll();

    @Select("SELECT * FROM `columns` WHERE column_id = #{columnId}")
    Columns selectByCid(int columnId);

    @Update("UPDATE `columns` SET parent_id = #{parentId}, name = #{name}, description = #{description}, image_url = #{imageUrl}, image_width = #{imageWidth}, image_height = #{imageHeight}, type = #{type}, created_time = #{createdTime}, updated_time = #{updatedTime} " +
            "WHERE column_id = #{columnId}")
    void updateColumn(Columns columns);

    @Delete("DELETE FROM `columns` WHERE column_id = #{columnId}")
    void deleteColumn(Integer columnId);

    @Select("SELECT * FROM `columns` WHERE parent_id IS NULL")
    List<Columns> selectParentColumns();

    @Select("SELECT * FROM `columns` WHERE parent_id = #{pid}")
    List<Columns> selectChildrenColumns(Integer pid);

   @Select("SELECT * FROM `columns` WHERE parent_id IS NOT NULL")
    List<Columns> selectAllChildrenColumns();
}
